package com.fms.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.fms.util.BaseContext;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    //数据插入时自动填入
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createDate", LocalDateTime::now, LocalDateTime.class);
        this.strictInsertFill(metaObject,"creator", BaseContext::getCurrentId, Long.class);
        this.strictUpdateFill(metaObject, "updateDate", LocalDateTime::now, LocalDateTime.class);
        this.strictUpdateFill(metaObject,"updater", BaseContext::getCurrentId, Long.class);
    }
    //数据更新时自动填入
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateDate", LocalDateTime::now, LocalDateTime.class);
        this.strictUpdateFill(metaObject,"updater", BaseContext::getCurrentId, Long.class);
    }
}
